﻿namespace Sidvall.AuthorizationManager.UI.Entities
{
	public sealed partial class AuthorizationScope
	{
		#region Public Members

		#region HasUser

		public bool HasUser
		{
			get
			{
				if (this.AuthorizationScopeUsers == null)
					return false;
				return this.AuthorizationScopeUsers.Count > 0;
			}
		}

		#endregion
		#region IsSelected

		private bool _IsSelected;
		public bool IsSelected
		{
			get
			{
				return _IsSelected;
			}
			set
			{
				_IsSelected = value;
				OnPropertyChanged("IsSelected", true, false);
			}
		}

		#endregion

		#region AddUser

		public void AddUser(string userId)
		{
			AuthorizationScopeUser item;

			if (this.AuthorizationScopeUsers == null)
				this.AuthorizationScopeUsers = new AuthorizationScopeUserCollection();
			item = new AuthorizationScopeUser()
			{
				UserId = userId,
				UserContext = this.DefaultUserContext,
			};
			if (this.AuthorizationScopeId != null)
				item.AuthorizationScopeId = this.AuthorizationScopeId.Value;
			this.AuthorizationScopeUsers.Add(item);
		}

		#endregion
		#region SetUserId

		public void SetUserId(string userId)
		{
			if (this.AuthorizationScopeUsers == null)
				return;
			foreach (var user in this.AuthorizationScopeUsers)
				user.UserId = userId;
		}

		#endregion

		#endregion
	}
}